package com.chain.galaxychain123.kotlionapp

import kotlin.reflect.KProperty

class BigSon {
//kotlin中变量默认访问修饰符是public，对应setter和getter也都是public
 var name="大头儿子" //默认name初始化
 var age =1 //默认age 初始化


   //属性age 的自定义get()
    get()=field

//属性age的自定义set()
   set(value) {
     field=value

     if(value>=18){
         println("${name}age=${age},已成年")
     }else{
         println("${name}age=${age},未成年")
     }
 }



   var yashuMoney:Int by SmallFather()


}




class SmallFather() {

    // BigSon的 属性 yashuMoney(默认0)
    var  yashuMoney:Int=0



    operator fun getValue(bigSon: BigSon,
                          property: KProperty<*>): Int {
        println("SmallFather的getValue被调用,获取当前修改的属性值yashuMoney:${property.name}"+"${yashuMoney}")
      return   yashuMoney?:0
    }

    operator fun setValue(bigSon: BigSon,
                          property: KProperty<*>,
                          value: Int) {


        println("SmallFather的setValue()被调用,"+"修改当前的属性value:${property.name}"+"${value}"
        )

        this.yashuMoney=value


    }








}












